package org.java.order.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.java.order.entity.Order;
/**
 * @author WHQ
 * @version 1.0
 * @date 2022-3-15 0015 下午 3:53
 */
public interface OrderMapper extends BaseMapper<Order> {
    /**
     * 创建订单
     * @return
     */
    @Insert("insert into user_order values (#{orderId},#{orderUserName},#{orderAddrId},#{orderMoney},#{orderCreateTime},#{orderState},#{orderTimeoutState})")
    public void createOrder(Order order);

    /**
     * 根据订单编号查询订单状态
     * @param tradeNum
     * @return
     */
    @Select("select order_state from user_order where order_id=#{tradeNum}")
    Boolean selectOrderStateByOrderId(@Param("tradeNum") String tradeNum);

    /**
     * 订单超时，修改订单超时状态
     * @param tradeNum
     */
    @Update("update user_order set order_timeout_state=0 where order_id=#{tradeNum}")
    void updateOrderTimeoutStateByOrderId(@Param("tradeNum") String tradeNum);

    /**
     * 支付成功以后，修改订单状态的方法
     * @param tradeNum
     * @return
     */
    @Update("update user_order set order_state=1 where order_id=#{tradeNum}")
    int modifyOrder(@Param("tradeNum") String tradeNum);
}
